//package com.csust.travel.controller;
//
//import cn.hutool.core.util.StrUtil;
//import com.csust.travel.common.Result;
//import com.csust.travel.entity.NewUsers;
//import com.csust.travel.entity.ResBean;
//import com.csust.travel.entity.User;
//import com.csust.travel.mapper.NewUsersMapper;
//import com.csust.travel.service.impl.CodeService;
//import com.csust.travel.service.impl.UserTokenService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.CrossOrigin;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.annotation.Resource;
//
//@RestController
//@CrossOrigin
//public class LoginController {
//    @Autowired
//    NewUsersMapper newUsersMapper;
//
//    @Resource
//    private UserTokenService userTokenService;
//
//    @Resource
//    private CodeService codeService;
//
//    @GetMapping("/")
//    public Result hello() {
//        return Result.success("success");
//    }
//
//    @PostMapping("/login")
//    public Result login(@RequestBody NewUsers newUsers) {
//        if (StrUtil.isBlank(newUsers.getUsername()) || StrUtil.isBlank(newUsers.getPassword())) {
//            return Result.error("数据输入不合法");
//        }
//        User newUsers1 = userTokenService.login(newUsers);
//        return new Result("200", "用户 " + newUsers.getUsername() + ", 登陆成功", newUsers1.getToken());
//    }
//
//    @PostMapping("/register")
//    public Result register(@RequestBody NewUsers newUsers) {
//        if (StrUtil.isBlank(newUsers.getUsername()) || StrUtil.isBlank(newUsers.getPassword())) {
//            return Result.error("数据输入不合法");
//        }
//        if (newUsers.getUsername().length() > 10 || newUsers.getPassword().length() > 15) {
//            return Result.error("数据输入不合法");
//        }
//        String email = newUsers.getEmail();
//        String code = newUsers.getCode();
//        System.out.println(code+" 0909");
//
//        // 验证验证码
//        if (!codeService.validateCode(email, code)) {
//            return Result.error("验证码无效或已过期");
//        }
//
//        NewUsers login = userTokenService.register(newUsers);
//        return Result.success(login);
//    }
//
//    @PostMapping("/verify")
//    public ResBean verify(@RequestBody NewUsers newUsers) {
//        String email = newUsers.getEmail();
//        String code = newUsers.getCode();
//        System.out.println(code+" 0909");
//
//        // 验证验证码
//        if (!codeService.validateCode(email, code)) {
//            return new ResBean(false,"验证码无效或已过期");
//        }
//
//        return new ResBean(true,"");
//    }
//
////    @PostMapping("/findPwd")
////    public ResBean findThree( @RequestBody UserParam3 param) {
////
////        String email = param.getEmail();
////        String newPwd = param.getNewPwd();
////
////        newUsersMapper.findPwd(newPwd,email);
////        try {
////            return new ResBean(true, null);
////        } catch (Exception e) {
////            e.printStackTrace();
////            return new ResBean(false, null);
////        }
////    }
//}
